*&---------------------------------------------------------------------*
*& 包含               ZFIU024_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_PROCESS_DATA .

  DATA:
    LV_TABIX            TYPE I,
    LV_INV_COUNT        TYPE I,
    LV_DO_TIMES         TYPE I,
    LV_TABIX_START      TYPE I,
    LV_TABIX_END        TYPE I,
    LV_ZKPSJ_BEGDA      TYPE SY-DATUM,
    LV_ZKPSJ_BEGDA_TMP  TYPE SY-DATUM,
    LV_ZKPSJ_BEGDA_TMP1 TYPE SY-DATUM,
    LV_ZKPSJ_ENDDA_TMP  TYPE SY-DATUM,
    LV_ZKPSJ_ENDDA      TYPE SY-DATUM,
    LV_TASK_NO          TYPE STRING,
    LS_MSG              TYPE BAPIRET2,
    LV_MSG_STR          TYPE STRING,
    LS_ZFIT078_HIS_DB   TYPE ZFIT078_HIS,
    LT_INVOICE_LIST     TYPE ZCLDT_INPUT_INVOICE_LIST_Q_TAB,
    LT_INVOICE_LIST_TMP TYPE ZCLDT_INPUT_INVOICE_LIST_Q_TAB,
    LT_ZFIT078_HIS_DB   TYPE STANDARD TABLE OF ZFIT078_HIS.

  DATA:
    LV_NEED_SYNCENTERACCOUNT      TYPE C,
    LV_NEED_SYNC_FLAG             TYPE C,
    LV_INV_CODE                   TYPE STRING,
    LV_INV_NO                     TYPE STRING,
    LV_INV_CODE_NO                TYPE STRING,
    LS_CONTENT_INVOICE_REIMBURSE  TYPE ZCL_DT_VAT_INVOICE_REIMBURSE_1,
    LS_CONTENT_SYNCENTERACCOUNT   TYPE ZCL_DT_SYNC_ENTER_ACCOUNT_REQ1,
    LS_CONTENT_CHECKLISTNEW_ITM   TYPE ZCL_DT_INVOICE_CHECK_LIST_NEW1,
    LT_CONTENT_CHECKLISTNEW_ITM   TYPE ZCL_DT_INVOICE_CHECK_LIST__TAB,
    LS_CONTENT_CHECKLISTNEW_INV   TYPE ZCL_DT_INVOICE_CHECK_LIST_NEW2,  "发票
    LS_CONTENT_CHECKLISTNEW_HG    TYPE ZCL_DT_INVOICE_CHECK_LIST_NEW2,  "海关缴款书
    LS_CONTENT_SUBMITACC_ITM      TYPE ZCLDT_SUB_CHA_RECORDED_DATA_R1,
    LT_CONTENT_SUBMITACC_ITM      TYPE ZCLDT_SUB_CHA_RECORDED_DAT_TAB,
    LS_CONTENT_SUBMITENTERACCOUNT TYPE ZCLDT_SUB_CHA_RECORDED_DATA_R2,
    LS_CONTENT_INV_CHECK_LIST_ITM TYPE ZCL_DT_QUERY_INV_CHECKLIST_REQ,
    LT_CONTENT_INV_CHECK_LIST_ITM TYPE ZCL_DT_QUERY_INV_CHECKLIST_TAB,
    LS_CONTENT_INV_CHECK_LIST     TYPE ZCL_DT_QUERY_INV_CHECKLIST_RE2,
    LT_INV_CHECK_LIST_TMP         TYPE ZCL_DT_QUERY_INV_CHECKLIS_TAB1,
    LT_INV_CHECK_LIST             TYPE ZCL_DT_QUERY_INV_CHECKLIS_TAB1.

  CHECK GV_ERROR IS INITIAL.

  IF GT_JSD_DATA[] IS NOT INITIAL AND P_SEND IS NOT INITIAL.

    "取发票原始数据
    SELECT *
      INTO TABLE @DATA(LT_ZFIT078_HEAD)
      FROM ZFIT078_HEAD
       FOR ALL ENTRIES IN @GT_JSD_DATA
     WHERE ZFPHM = @GT_JSD_DATA-ZYSFPHM.

    SELECT *
      INTO TABLE @DATA(LT_ZFIT078_HIS)
      FROM ZFIT078_HIS
       FOR ALL ENTRIES IN @GT_JSD_DATA
     WHERE ZFPHM = @GT_JSD_DATA-ZYSFPHM.

    SORT LT_ZFIT078_HEAD BY ZKPSJ ASCENDING.
    READ TABLE LT_ZFIT078_HEAD INTO DATA(LS_ZFIT078_HEAD) INDEX 1.
    LV_ZKPSJ_BEGDA = LS_ZFIT078_HEAD-ZKPSJ.
    LV_ZKPSJ_BEGDA_TMP = LS_ZFIT078_HEAD-ZKPSJ.

    CLEAR LS_ZFIT078_HEAD.
    SORT LT_ZFIT078_HEAD BY ZKPSJ DESCENDING .
    READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD INDEX 1.
    LV_ZKPSJ_ENDDA = LS_ZFIT078_HEAD-ZKPSJ.
    LV_ZKPSJ_ENDDA_TMP = LS_ZFIT078_HEAD-ZKPSJ.

    "获取发票列表数据开始
**********************************************************************
    LV_ZKPSJ_BEGDA_TMP1 = LV_ZKPSJ_BEGDA + 90.
    IF LV_ZKPSJ_BEGDA_TMP1 <  LV_ZKPSJ_ENDDA. "获取发票列表不能大于91天

      LOOP AT LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD.
        "开始调用诺诺平台
        "通过接口获取最新的发票入账状态
        CLEAR LS_MSG.
        REFRESH LT_INVOICE_LIST_TMP.
        CALL FUNCTION 'ZFIFM_INV_GET_LIST'
          EXPORTING
            IV_ZYSFPHM          = LS_ZFIT078_HEAD-ZFPHM
            IV_BEGDA            = LS_ZFIT078_HEAD-ZKPSJ
            IV_ENDDA            = LS_ZFIT078_HEAD-ZKPSJ
            IV_ENTER_ACCOUNT_NO = SPACE
          IMPORTING
            ES_MSG              = LS_MSG
            ET_INV_LIST         = LT_INVOICE_LIST_TMP.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-获取发票列表失败，原因：',  LV_MSG_STR.
          EXIT.
        ENDIF.

        APPEND LINES OF LT_INVOICE_LIST_TMP TO LT_INVOICE_LIST.
      ENDLOOP.

      IF LS_MSG-TYPE = 'E'.
        RETURN.
      ENDIF.

    ELSE.
      "开始调用诺诺平台
      "通过接口获取最新的发票入账状态
      CLEAR LS_MSG.
      CALL FUNCTION 'ZFIFM_INV_GET_LIST'
        EXPORTING
          "IV_ZYSFPHM  = S_ZFPHM-LOW
          IV_BEGDA            = LV_ZKPSJ_BEGDA
          IV_ENDDA            = LV_ZKPSJ_ENDDA
          IV_ENTER_ACCOUNT_NO = SPACE
        IMPORTING
          ES_MSG              = LS_MSG
          ET_INV_LIST         = LT_INVOICE_LIST.
      IF LS_MSG-TYPE = 'E'.
        LV_MSG_STR = LS_MSG-MESSAGE.
        WRITE: / '诺诺发票接口-获取发票列表失败，原因：',  LV_MSG_STR.
        RETURN.
      ENDIF.
    ENDIF.

    "删除取出多余的发票
    SORT LT_ZFIT078_HEAD BY ZFPHM.
    LOOP AT LT_INVOICE_LIST INTO DATA(LS_INVOICE_LIST).
      LV_TABIX = SY-TABIX.

      CLEAR LV_INV_CODE_NO.
      IF LS_INVOICE_LIST-ELEC_INVOICE_NUMBER IS NOT INITIAL.
        LV_INV_CODE_NO = LS_INVOICE_LIST-ELEC_INVOICE_NUMBER.
      ELSE.
        CONDENSE:
          LS_INVOICE_LIST-INVOICE_CODE,
          LS_INVOICE_LIST-INVOICE_NO.
        LV_INV_CODE_NO = LS_INVOICE_LIST-INVOICE_CODE && '-' && LS_INVOICE_LIST-INVOICE_NO.
      ENDIF.

      CONDENSE LV_INV_CODE_NO.

      CLEAR LS_ZFIT078_HEAD.
      READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
        WITH KEY ZFPHM = LV_INV_CODE_NO
        BINARY SEARCH.
      IF SY-SUBRC <> 0.
        DELETE LT_INVOICE_LIST INDEX LV_TABIX.
      ENDIF.
    ENDLOOP.

    IF LT_INVOICE_LIST[] IS INITIAL.
      WRITE: / '无发票数据'.
      RETURN.
    ENDIF.
    "获取发票列表数据结束
**********************************************************************

    "诺诺发票接口-同步所属期
    CLEAR:
      LV_TASK_NO,
      LS_MSG.
    CALL FUNCTION 'ZFIFM_INV_SYNC_PERIOD'
      IMPORTING
        ES_MSG     = LS_MSG
        EV_TASK_NO = LV_TASK_NO.

    IF LS_MSG-TYPE = 'E'.
      LV_MSG_STR = LS_MSG-MESSAGE.
      WRITE: / '诺诺发票接口-同步所属期失败，原因：',  LV_MSG_STR.
      RETURN.
    ENDIF.

    "获取发票勾选抵扣数据开始
**********************************************************************
    SORT LT_ZFIT078_HEAD BY ZFPHM.
    LOOP AT GT_JSD_DATA INTO DATA(LS_JSD_DATA).
      CLEAR:
         LV_INV_CODE,
         LV_INV_NO.
      IF LS_JSD_DATA-ZYSFPHM CS '-'.
        SPLIT LS_JSD_DATA-ZYSFPHM AT '-' INTO LV_INV_CODE LV_INV_NO.
      ENDIF.

      IF LV_INV_NO IS INITIAL.
        LV_INV_NO = LS_JSD_DATA-ZYSFPHM.
      ENDIF.

      CLEAR LS_ZFIT078_HEAD.
      READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
        WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
        BINARY SEARCH.
      "普票不需要勾选抵扣
      IF LS_ZFIT078_HEAD-INVOICE_LINE CS 's' OR  "专用发票(纸质)
         LS_ZFIT078_HEAD-INVOICE_LINE CS 'b' OR  "专用发票(电子)
        LS_ZFIT078_HEAD-INVOICE_LINE CS 'bs' OR  "电子发票（增值税专用发票)
        LS_ZFIT078_HEAD-INVOICE_LINE CS 'es' OR  "数电纸质专用发票
        LS_ZFIT078_HEAD-INVOICE_LINE CS '17' .  "海关缴款书

        CLEAR LS_CONTENT_INV_CHECK_LIST_ITM.
        LS_CONTENT_INV_CHECK_LIST_ITM-INVOICE_CODE = LV_INV_CODE.
        LS_CONTENT_INV_CHECK_LIST_ITM-INVOICE_NUMBER = LV_INV_NO.

        "APPEND LS_CONTENT_INV_CHECK_LIST_ITM TO LS_CONTENT_INV_CHECK_LIST-INVOICE_INFO.
        APPEND LS_CONTENT_INV_CHECK_LIST_ITM TO LT_CONTENT_INV_CHECK_LIST_ITM.
      ENDIF.
    ENDLOOP.

    IF LT_CONTENT_INV_CHECK_LIST_ITM[] IS NOT INITIAL.

      SORT LT_CONTENT_INV_CHECK_LIST_ITM BY INVOICE_CODE INVOICE_NUMBER.
      DELETE ADJACENT DUPLICATES FROM LT_CONTENT_INV_CHECK_LIST_ITM COMPARING INVOICE_CODE INVOICE_NUMBER.

      LV_INV_COUNT = LINES( LT_CONTENT_INV_CHECK_LIST_ITM ).
      LV_DO_TIMES = CEIL( LV_INV_COUNT / '100.00' ).

      REFRESH: LT_INV_CHECK_LIST[].
      "通过接口获取最新的发票抵扣勾选状态
      DO LV_DO_TIMES TIMES.

        CLEAR LS_CONTENT_INV_CHECK_LIST.
        REFRESH LS_CONTENT_INV_CHECK_LIST-INVOICE_INFO[].

        LV_TABIX_START = 1 + 100 * ( SY-INDEX - 1 ).
        LV_TABIX_END = LV_TABIX_START + 99.
        IF LV_TABIX_END > LV_INV_COUNT.
          LV_TABIX_END = LV_INV_COUNT.
        ENDIF.

        LS_CONTENT_INV_CHECK_LIST-JKSBZ = '1'. "缴款书标志0-仅发票 1-发票和缴款书 2-发票和缴款书和代扣代缴完税凭证
        APPEND LINES OF LT_CONTENT_INV_CHECK_LIST_ITM FROM LV_TABIX_START TO LV_TABIX_END TO LS_CONTENT_INV_CHECK_LIST-INVOICE_INFO[].

        CLEAR: LS_MSG.
        REFRESH: LT_INV_CHECK_LIST_TMP[].
        CALL FUNCTION 'ZFIFM_INV_QUERY_CHECK_LIST'
          EXPORTING
            IS_CONTENT        = LS_CONTENT_INV_CHECK_LIST
          IMPORTING
            ES_MSG            = LS_MSG
            ET_INV_CHECK_LIST = LT_INV_CHECK_LIST_TMP.

        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-查询勾选抵扣失败，原因：',  LV_MSG_STR.
          EXIT.
        ENDIF.

        APPEND LINES OF LT_INV_CHECK_LIST_TMP TO LT_INV_CHECK_LIST[].
      ENDDO.

      IF LS_MSG-TYPE = 'E'.
        RETURN.
      ENDIF.

    ENDIF.
    "获取发票勾选抵扣数据结束
**********************************************************************

    "并合并发票号码、发票代码
    LOOP AT LT_INVOICE_LIST INTO LS_INVOICE_LIST."发票列表数据，入账、报销状态
      LV_TABIX = SY-TABIX.

      IF LS_INVOICE_LIST-INVOICE_CODE IS NOT INITIAL.
        CONDENSE:
          LS_INVOICE_LIST-INVOICE_CODE,
          LS_INVOICE_LIST-INVOICE_NO.
        LS_INVOICE_LIST-ELEC_INVOICE_NUMBER = LS_INVOICE_LIST-INVOICE_CODE && '-' && LS_INVOICE_LIST-INVOICE_NO.
      ENDIF.

      MODIFY LT_INVOICE_LIST FROM LS_INVOICE_LIST INDEX LV_TABIX.
    ENDLOOP.

    LOOP AT LT_INV_CHECK_LIST INTO DATA(LS_INV_CHECK_LIST)."发票勾选抵扣数据
      IF LS_INV_CHECK_LIST-INVOICE_CODE IS NOT INITIAL.
        CONDENSE:
          LS_INV_CHECK_LIST-INVOICE_CODE,
          LS_INV_CHECK_LIST-INVOICE_NUMBER.
        LS_INV_CHECK_LIST-ELEC_INVOICE_NUMBER = LS_INV_CHECK_LIST-INVOICE_CODE && '-' && LS_INV_CHECK_LIST-INVOICE_NUMBER.
      ENDIF.
      MODIFY LT_INV_CHECK_LIST FROM LS_INV_CHECK_LIST.
    ENDLOOP.

    SORT LT_ZFIT078_HEAD BY ZFPHM.
    SORT LT_INVOICE_LIST BY ELEC_INVOICE_NUMBER.
    SORT LT_INV_CHECK_LIST BY ELEC_INVOICE_NUMBER.

    "获取入账、报销、抵扣勾选结果，并更新历史记录表开始
**********************************************************************
    IF P_SYSNC IS NOT INITIAL."获取入账、抵扣勾选结果
      SORT LT_ZFIT078_HIS BY ZFPHM CHDAT DESCENDING CHTIM DESCENDING.

      LOOP AT GT_JSD_DATA INTO LS_JSD_DATA.
        CLEAR LS_ZFIT078_HEAD.
        READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
          WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
          BINARY SEARCH.
        IF SY-SUBRC = 0.

          CLEAR LS_ZFIT078_HIS_DB.

          "查询入账\报销数据
          CLEAR LS_INVOICE_LIST.
          READ TABLE LT_INVOICE_LIST INTO LS_INVOICE_LIST
            WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
            BINARY SEARCH.
          IF SY-SUBRC = 0.
            "当前税局入账状态（01未入账 02已入账-企业所得税税前扣除 03已入账-企业所得税不扣除 06-入账撤销）
            CONDENSE: LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS.

            READ TABLE LT_ZFIT078_HIS INTO DATA(LS_ZFIT078_HIS)
              WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            "防止重复插入，发票历史记录表里面最后一条记录状态非诺诺平台查到的状态
            IF LS_ZFIT078_HIS-ZNONO_RZZT <> LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS.
              LS_ZFIT078_HIS_DB = LS_ZFIT078_HIS.
              LS_ZFIT078_HIS_DB-CHNAM = SY-UNAME.
              LS_ZFIT078_HIS_DB-CHDAT = SY-DATUM.
              LS_ZFIT078_HIS_DB-CHTIM = SY-UZEIT.
              LS_ZFIT078_HIS_DB-ZNONO_RZZT = LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS.
            ENDIF.

            CONDENSE: LS_INVOICE_LIST-REIMBURSEMENT_STATUS.
            "防止重复插入，发票历史记录表里面最后一条记录状态非诺诺平台查到的状态
            IF LS_ZFIT078_HIS-ZNONO_BXZT <> LS_INVOICE_LIST-REIMBURSEMENT_STATUS.
              IF LS_ZFIT078_HIS_DB IS INITIAL.
                LS_ZFIT078_HIS_DB = LS_ZFIT078_HIS.
                LS_ZFIT078_HIS_DB-CHNAM = SY-UNAME.
                LS_ZFIT078_HIS_DB-CHDAT = SY-DATUM.
                LS_ZFIT078_HIS_DB-CHTIM = SY-UZEIT.
              ENDIF.
              LS_ZFIT078_HIS_DB-ZNONO_BXZT = LS_INVOICE_LIST-REIMBURSEMENT_STATUS.
            ENDIF.
          ENDIF.

          "查询抵扣勾选数据
          CLEAR LS_INV_CHECK_LIST.
          READ TABLE LT_INV_CHECK_LIST INTO LS_INV_CHECK_LIST
            WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
            BINARY SEARCH.
          IF SY-SUBRC = 0.
            "勾选状态：0-未勾选1-已勾选 -1-采集缴款书,不能勾选
            CONDENSE: LS_INV_CHECK_LIST-CHECK_STATUS.

            CLEAR LS_ZFIT078_HIS.
            READ TABLE LT_ZFIT078_HIS INTO LS_ZFIT078_HIS
                         WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
                         BINARY SEARCH.
            "防止重复插入，发票历史记录表里面最后一条记录状态非诺诺平台查到的状态
            IF LS_ZFIT078_HIS-ZNONO_GXZT <> LS_INV_CHECK_LIST-CHECK_STATUS.
              IF LS_ZFIT078_HIS_DB IS INITIAL.
                LS_ZFIT078_HIS_DB = LS_ZFIT078_HIS.
                LS_ZFIT078_HIS_DB-CHNAM = SY-UNAME.
                LS_ZFIT078_HIS_DB-CHDAT = SY-DATUM.
                LS_ZFIT078_HIS_DB-CHTIM = SY-UZEIT.
              ENDIF.
              LS_ZFIT078_HIS_DB-ZNONO_GXZT = LS_INV_CHECK_LIST-CHECK_STATUS.
            ENDIF.
          ENDIF.

          IF LS_ZFIT078_HIS_DB IS NOT INITIAL.
            APPEND LS_ZFIT078_HIS_DB TO LT_ZFIT078_HIS_DB.
          ENDIF.

        ENDIF.
        CLEAR:
          LS_ZFIT078_HIS.
      ENDLOOP.

      IF LT_ZFIT078_HIS_DB[] IS NOT INITIAL.
        MODIFY ZFIT078_HIS FROM TABLE LT_ZFIT078_HIS_DB.
        COMMIT WORK AND WAIT.

        WRITE: / '入账结果、抵扣勾选结果已更新到发票处理历史表'.

      ELSE.
        WRITE: / '未查到最新的发票入账结果、抵扣勾选结果'.
      ENDIF.

      "获取入账、报销、抵扣勾选结果，并更新历史记录表结束
**********************************************************************


**********************************************************************
    ELSE.  "增值税写入报销、提交入账、同步入账、抵扣勾选

      "增值税写入报销
      LOOP AT GT_JSD_DATA INTO LS_JSD_DATA WHERE JSDZT = '05'.
        CLEAR:
          LV_INV_CODE,
          LV_INV_NO.

        IF LS_JSD_DATA-ZYSFPHM CS '-'.
          SPLIT LS_JSD_DATA-ZYSFPHM AT '-' INTO LV_INV_CODE LV_INV_NO.
        ENDIF.

        IF LV_INV_NO IS INITIAL.
          LV_INV_NO = LS_JSD_DATA-ZYSFPHM.
        ENDIF.

        CLEAR LS_ZFIT078_HEAD.
        READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
          WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
          BINARY SEARCH.
        IF SY-SUBRC = 0.
          IF LS_ZFIT078_HEAD-INVOICE_LINE NS '17' .  "海关缴款书无需入账、无需报销

            "查询报销数据
            CLEAR LS_INVOICE_LIST.
            READ TABLE LT_INVOICE_LIST INTO LS_INVOICE_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            IF SY-SUBRC = 0.

              "准备报销数据
              "报销状态：1未报销，2已报销
              CONDENSE: LS_INVOICE_LIST-REIMBURSEMENT_STATUS.
              IF LS_INVOICE_LIST-REIMBURSEMENT_STATUS IS INITIAL OR LS_INVOICE_LIST-REIMBURSEMENT_STATUS = '1'.

                CLEAR:LS_CONTENT_INVOICE_REIMBURSE.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_CODE = LV_INV_CODE.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_NO = LV_INV_NO.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_DATE = LS_ZFIT078_HEAD-ZKPSJ+0(4) && '-' && LS_ZFIT078_HEAD-ZKPSJ+4(2) && '-' && LS_ZFIT078_HEAD-ZKPSJ+6(2).
                LS_CONTENT_INVOICE_REIMBURSE-TOTAL_AMOUNT = LS_ZFIT078_HEAD-ZHSJE.
                LS_CONTENT_INVOICE_REIMBURSE-TAX_AMOUNT = LS_ZFIT078_HEAD-ZHJSE.
                LS_CONTENT_INVOICE_REIMBURSE-EXCLUDETAX_AMOUNT = LS_ZFIT078_HEAD-ZBHSJE.
                "LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REMARK = ''.
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-VOUCHER_NO = LS_JSD_DATA-BUKRS && LS_JSD_DATA-BELNR  && LS_JSD_DATA-GJAHR.
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-OPERATE_TYPE = '1'. "报销方式0:取消报销、1:已报销、2:编辑报销。默认值1。
                " LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-OPERATION_TIME = SY-DATUM+0(4) && '-' && SY-DATUM+4(2) && '-' && SY-DATUM+6(2).

                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_TYPE = '14'. "报销类型编码
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_TYPE_DESC = '其他'.

                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_NAME = LS_JSD_DATA-CRNAM. "报销人名称
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_AMOUNT = LS_ZFIT078_HEAD-ZHSJE.

                CONDENSE:
                  LS_CONTENT_INVOICE_REIMBURSE-TOTAL_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-TAX_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-EXCLUDETAX_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_AMOUNT.

                CLEAR LS_MSG.
                CALL FUNCTION 'ZFIFM_INV_REIMBURSE_OPERATE'
                  EXPORTING
                    IS_CONTENT = LS_CONTENT_INVOICE_REIMBURSE
                  IMPORTING
                    ES_MSG     = LS_MSG.

                IF LS_MSG-TYPE = 'E'.
                  EXIT.
                ENDIF.

              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.

      IF LS_CONTENT_INVOICE_REIMBURSE IS NOT INITIAL.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-提交报销失败，原因：',  LS_CONTENT_INVOICE_REIMBURSE-INVOICE_NO, LS_CONTENT_INVOICE_REIMBURSE-INVOICE_CODE, LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-提交报销已成功执行'.
        ENDIF.
      ENDIF.


      "最终状态为已经过账发票，进行入账、同步入账、提交进项抵扣
      LOOP AT GT_JSD_DATA INTO LS_JSD_DATA WHERE JSDZT = '05'.
        CLEAR:
          LV_INV_CODE,
          LV_INV_NO.

        IF LS_JSD_DATA-ZYSFPHM CS '-'.
          SPLIT LS_JSD_DATA-ZYSFPHM AT '-' INTO LV_INV_CODE LV_INV_NO.
        ENDIF.

        IF LV_INV_NO IS INITIAL.
          LV_INV_NO = LS_JSD_DATA-ZYSFPHM.
        ENDIF.

        CLEAR LS_ZFIT078_HEAD.
        READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
          WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
          BINARY SEARCH.
        IF SY-SUBRC = 0.
          IF LS_ZFIT078_HEAD-INVOICE_LINE NS '17' .  "海关缴款书无需入账

            "查询入账、报销数据
            CLEAR LS_INVOICE_LIST.
            READ TABLE LT_INVOICE_LIST INTO LS_INVOICE_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            IF SY-SUBRC = 0.

              "准备入账数据
              "当前税局入账状态（01未入账 02已入账-企业所得税税前扣除 03已入账-企业所得税不扣除 06-入账撤销）
              CONDENSE: LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS.
              IF LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS IS INITIAL OR LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS = '01'
                OR LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS = '06'.

                IF LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS = '06'.
                  LS_CONTENT_SUBMITENTERACCOUNT-ENTER_ACCOUNT_MODE = '2'. "1：提交入账（原始状态为未入账） 2：变更入账（原始状态为已入账和入账撤销
                ELSE.
                  LS_CONTENT_SUBMITENTERACCOUNT-ENTER_ACCOUNT_MODE = '1'. "1：提交入账（原始状态为未入账） 2：变更入账（原始状态为已入账和入账撤销
                ENDIF.

                CLEAR LS_CONTENT_SUBMITACC_ITM.
                IF LV_INV_CODE IS NOT INITIAL.
                  LS_CONTENT_SUBMITACC_ITM-INVOICE_CODE = LV_INV_CODE.
                  LS_CONTENT_SUBMITACC_ITM-INVOICE_NUMBER = LV_INV_NO.
                ELSE.
                  LS_CONTENT_SUBMITACC_ITM-ELEC_INVOICE_NUMBER = LV_INV_NO.
                ENDIF.

                LS_CONTENT_SUBMITACC_ITM-ENTER_ACCOUNT_STATUS = '02'.  "入账状态（02：已入账-企业所得税税前扣除；03：已入账-企业所得税不扣除；06：撤销入账）
                LS_CONTENT_SUBMITACC_ITM-ENTER_ACCOUNT_TIME = SY-DATUM+0(4) && '-' && SY-DATUM+4(2) && '-' && SY-DATUM+6(2).
                APPEND LS_CONTENT_SUBMITACC_ITM TO LS_CONTENT_SUBMITENTERACCOUNT-INV_DATA.
              ENDIF.
            ENDIF.
          ENDIF.


          "查询抵扣勾选数据 增值税发票才会调用
          IF LS_ZFIT078_HEAD-INVOICE_LINE CS 's' OR  "专用发票(纸质)
             LS_ZFIT078_HEAD-INVOICE_LINE CS 'b' OR  "专用发票(电子)
            LS_ZFIT078_HEAD-INVOICE_LINE CS 'bs' OR  "电子发票（增值税专用发票)
            LS_ZFIT078_HEAD-INVOICE_LINE CS 'es' OR  "数电纸质专用发票
            LS_ZFIT078_HEAD-INVOICE_LINE CS '17' .  "海关缴款书

            CLEAR LS_INV_CHECK_LIST.
            READ TABLE LT_INV_CHECK_LIST INTO LS_INV_CHECK_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            "准备抵扣勾选数据
            IF LS_INV_CHECK_LIST-CHECK_STATUS = '0' OR LS_INV_CHECK_LIST-CHECK_STATUS IS INITIAL. "勾选状态：0-未勾选1-已勾选， -1-采集缴款书,不能勾选. 或者未查到数据
              IF LS_ZFIT078_HEAD-INVOICE_LINE CS '17'. "海关缴款书
                LS_CONTENT_CHECKLISTNEW_HG-JKSBZ = '1'. "缴款书标志0-勾选发票 1-勾选缴款书 2-代扣代缴完税凭证。不传默认0
                LS_CONTENT_CHECKLISTNEW_HG-GX_USER_NAME = 'VIM'. "勾选人名称
                LS_CONTENT_CHECKLISTNEW_HG-DEDUCTIBLE_MODE = '1'. "1：抵扣勾选（默认） -1：取消抵扣勾选 4：不抵扣勾选 -4：取消不抵扣勾选 5：退税勾选 -5：取消退税勾选

                CLEAR LS_CONTENT_CHECKLISTNEW_ITM.
                LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_CODE = LV_INV_CODE.
                LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_NUM = LV_INV_NO.
                APPEND LS_CONTENT_CHECKLISTNEW_ITM TO LS_CONTENT_CHECKLISTNEW_HG-INV_DATA.

              ELSE.
                LS_CONTENT_CHECKLISTNEW_INV-JKSBZ = '0'.             "缴款书标志0-勾选发票 1-勾选缴款书 2-代扣代缴完税凭证。不传默认0
                LS_CONTENT_CHECKLISTNEW_INV-GX_USER_NAME = 'VIM'.    "勾选人名称
                LS_CONTENT_CHECKLISTNEW_INV-DEDUCTIBLE_MODE = '1'. "1：抵扣勾选（默认） -1：取消抵扣勾选 4：不抵扣勾选 -4：取消不抵扣勾选 5：退税勾选 -5：取消退税勾选

                CLEAR LS_CONTENT_CHECKLISTNEW_ITM.
                LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_CODE = LV_INV_CODE.
                LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_NUM = LV_INV_NO.
                APPEND LS_CONTENT_CHECKLISTNEW_ITM TO LS_CONTENT_CHECKLISTNEW_INV-INV_DATA.
              ENDIF.
            ENDIF.
          ENDIF.

        ENDIF.
      ENDLOOP.

      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL OR LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL
        OR LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.
        LV_NEED_SYNC_FLAG = 'X'.
        WRITE: /.
        WRITE: / '开始进行诺诺平台：提交入账、提交抵扣勾选..............'.
      ENDIF.


      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL.
        LV_NEED_SYNCENTERACCOUNT = 'X'.

        LT_CONTENT_SUBMITACC_ITM[] = LS_CONTENT_SUBMITENTERACCOUNT-INV_DATA[].
        LV_INV_COUNT = LINES( LT_CONTENT_SUBMITACC_ITM[] ).
        LV_DO_TIMES = CEIL( LV_INV_COUNT / '100.00' ).

        DO LV_DO_TIMES TIMES."发票数量不能超过100
          LV_TABIX_START = 1 + 100 * ( SY-INDEX - 1 ).
          LV_TABIX_END = LV_TABIX_START + 99.
          IF LV_TABIX_END > LV_INV_COUNT.
            LV_TABIX_END = LV_INV_COUNT.
          ENDIF.

          REFRESH LS_CONTENT_SUBMITENTERACCOUNT-INV_DATA[].
          APPEND LINES OF LT_CONTENT_SUBMITACC_ITM[] FROM LV_TABIX_START TO LV_TABIX_END TO LS_CONTENT_SUBMITENTERACCOUNT-INV_DATA[].

          "诺诺发票接口-提交/变更入账数据
          CLEAR: LS_MSG.
          CALL FUNCTION 'ZFIFM_INV_SUBMITENTERACCOUNT'
            EXPORTING
              IS_CONTENT = LS_CONTENT_SUBMITENTERACCOUNT
            IMPORTING
              ES_MSG     = LS_MSG.
          IF LS_MSG-TYPE = 'E'.
            LV_MSG_STR = LS_MSG-MESSAGE.
            WRITE: / '诺诺发票接口-提交入账数据失败，原因：',  LV_MSG_STR.
            EXIT.
          ELSE.
            WRITE: / '诺诺发票接口-提交入账数据已成功执行'.
          ENDIF.
        ENDDO.

        IF LS_MSG-TYPE = 'E'.
          RETURN.
        ENDIF.
      ENDIF.


      "诺诺发票接口-勾选抵扣-发票数据
      IF LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL.

        LT_CONTENT_CHECKLISTNEW_ITM[] = LS_CONTENT_CHECKLISTNEW_INV-INV_DATA[].

        LV_INV_COUNT = LINES( LT_CONTENT_CHECKLISTNEW_ITM[] ).
        LV_DO_TIMES = CEIL( LV_INV_COUNT / '100.00' ).

        DO LV_DO_TIMES TIMES."发票数量不能超过100
          LV_TABIX_START = 1 + 100 * ( SY-INDEX - 1 ).
          LV_TABIX_END = LV_TABIX_START + 99.
          IF LV_TABIX_END > LV_INV_COUNT.
            LV_TABIX_END = LV_INV_COUNT.
          ENDIF.

          REFRESH LS_CONTENT_CHECKLISTNEW_INV-INV_DATA[].
          APPEND LINES OF LT_CONTENT_CHECKLISTNEW_ITM FROM LV_TABIX_START TO LV_TABIX_END TO LS_CONTENT_CHECKLISTNEW_INV-INV_DATA[].

          CLEAR:
          LS_MSG,
          LV_TASK_NO.
          CALL FUNCTION 'ZFIFM_INV_CHECK_LIST_NEW'
            EXPORTING
              IS_CONTENT = LS_CONTENT_CHECKLISTNEW_INV
            IMPORTING
              ES_MSG     = LS_MSG
              EV_TASK_NO = LV_TASK_NO.
          IF LS_MSG-TYPE = 'E'.
            LV_MSG_STR = LS_MSG-MESSAGE.
            WRITE: / '诺诺发票接口-提交勾选抵扣(发票数据)失败，原因：',  LV_MSG_STR.
            EXIT..
          ELSE.
            WRITE: / '诺诺发票接口-提交勾选抵扣(发票数据)已成功执行'.
          ENDIF.
        ENDDO.

        IF LS_MSG-TYPE = 'E'.
          RETURN.
        ENDIF.
      ENDIF.

      "诺诺发票接口-勾选抵扣-海关缴款书数据
      IF LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.
        CLEAR:
          LS_MSG,
          LV_TASK_NO.
        CALL FUNCTION 'ZFIFM_INV_CHECK_LIST_NEW'
          EXPORTING
            IS_CONTENT = LS_CONTENT_CHECKLISTNEW_HG
          IMPORTING
            ES_MSG     = LS_MSG
            EV_TASK_NO = LV_TASK_NO.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-提交勾选抵扣(海关缴款书数据)失败，原因：',  LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-提交勾选抵扣(海关缴款书数据)已成功执行'.
        ENDIF.
      ENDIF.

      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL OR LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL
        OR LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.
        WRITE: / '已完成诺诺平台：提交入账、提交抵扣勾选..............'.
        WRITE: /.
      ENDIF.

      CLEAR:
        LS_CONTENT_INVOICE_REIMBURSE,
        LS_CONTENT_SUBMITENTERACCOUNT,
        LS_CONTENT_CHECKLISTNEW_INV,
        LS_CONTENT_CHECKLISTNEW_HG.

      "增值税写入报销
      LOOP AT GT_JSD_DATA INTO LS_JSD_DATA WHERE JSDZT <> '05'.
        CLEAR:
          LV_INV_CODE,
          LV_INV_NO.

        IF LS_JSD_DATA-ZYSFPHM CS '-'.
          SPLIT LS_JSD_DATA-ZYSFPHM AT '-' INTO LV_INV_CODE LV_INV_NO.
        ENDIF.

        IF LV_INV_NO IS INITIAL.
          LV_INV_NO = LS_JSD_DATA-ZYSFPHM.
        ENDIF.

        CLEAR LS_ZFIT078_HEAD.
        READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
          WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
          BINARY SEARCH.
        IF SY-SUBRC = 0.
          IF LS_ZFIT078_HEAD-INVOICE_LINE NS '17' .  "海关缴款书无需入账、无需报销

            "查询报销数据
            CLEAR LS_INVOICE_LIST.
            READ TABLE LT_INVOICE_LIST INTO LS_INVOICE_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            IF SY-SUBRC = 0.

              "准备报销数据
              "报销状态：1未报销，2已报销
              CONDENSE: LS_INVOICE_LIST-REIMBURSEMENT_STATUS.
              IF LS_INVOICE_LIST-REIMBURSEMENT_STATUS = '2'.

                CLEAR:LS_CONTENT_INVOICE_REIMBURSE.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_CODE = LV_INV_CODE.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_NO = LV_INV_NO.
                LS_CONTENT_INVOICE_REIMBURSE-INVOICE_DATE = LS_ZFIT078_HEAD-ZKPSJ+0(4) && '-' && LS_ZFIT078_HEAD-ZKPSJ+4(2) && '-' && LS_ZFIT078_HEAD-ZKPSJ+6(2).
                LS_CONTENT_INVOICE_REIMBURSE-TOTAL_AMOUNT = LS_ZFIT078_HEAD-ZHSJE.
                LS_CONTENT_INVOICE_REIMBURSE-TAX_AMOUNT = LS_ZFIT078_HEAD-ZHJSE.
                LS_CONTENT_INVOICE_REIMBURSE-EXCLUDETAX_AMOUNT = LS_ZFIT078_HEAD-ZBHSJE.
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REMARK = 'VIM'.
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-VOUCHER_NO = LS_JSD_DATA-BUKRS && LS_JSD_DATA-BELNR  && LS_JSD_DATA-GJAHR.
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-OPERATE_TYPE = '0'. "报销方式0:取消报销、1:已报销、2:编辑报销。默认值1。
                " LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-OPERATION_TIME = SY-DATUM+0(4) && '-' && SY-DATUM+4(2) && '-' && SY-DATUM+6(2).

                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_TYPE = '14'. "报销类型编码
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_TYPE_DESC = '其他'.

                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_NAME = LS_JSD_DATA-CRNAM. "报销人名称
                LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_AMOUNT = LS_ZFIT078_HEAD-ZHSJE.

                CONDENSE:
                  LS_CONTENT_INVOICE_REIMBURSE-TOTAL_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-TAX_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-EXCLUDETAX_AMOUNT,
                  LS_CONTENT_INVOICE_REIMBURSE-REIMBURSEMENT_INFO-REIMBURSEMENT_AMOUNT.

                CLEAR LS_MSG.
                CALL FUNCTION 'ZFIFM_INV_REIMBURSE_OPERATE'
                  EXPORTING
                    IS_CONTENT = LS_CONTENT_INVOICE_REIMBURSE
                  IMPORTING
                    ES_MSG     = LS_MSG.

                IF LS_MSG-TYPE = 'E'.
                  EXIT.
                ENDIF.

              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.

      IF LS_CONTENT_INVOICE_REIMBURSE IS NOT INITIAL.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-撤销入账报销失败，原因：',  LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-撤销入账报销已成功执行'.
        ENDIF.
      ENDIF.

      "非05的状态，包含过账凭证的结算单为过账后冲销的发票
      LOOP AT GT_JSD_DATA INTO LS_JSD_DATA WHERE JSDZT <> '05'.
        CLEAR:
          LV_INV_CODE,
          LV_INV_NO.

        IF LS_JSD_DATA-ZYSFPHM CS '-'.
          SPLIT LS_JSD_DATA-ZYSFPHM AT '-' INTO LV_INV_CODE LV_INV_NO.
        ENDIF.

        IF LV_INV_NO IS INITIAL.
          LV_INV_NO = LS_JSD_DATA-ZYSFPHM.
        ENDIF.

        CLEAR LS_ZFIT078_HEAD.
        READ TABLE LT_ZFIT078_HEAD INTO LS_ZFIT078_HEAD
          WITH KEY ZFPHM = LS_JSD_DATA-ZYSFPHM
          BINARY SEARCH.
        IF SY-SUBRC = 0.
          IF LS_ZFIT078_HEAD-INVOICE_LINE NS '17' .  "海关缴款书无需入账

            "查询入账数据
            CLEAR LS_INVOICE_LIST.
            READ TABLE LT_INVOICE_LIST INTO LS_INVOICE_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            IF SY-SUBRC = 0.

              "准备入账数据
              "当前税局入账状态（01未入账 02已入账-企业所得税税前扣除 03已入账-企业所得税不扣除 06-入账撤销）
              CONDENSE: LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS.
              IF  LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS = '02' OR LS_INVOICE_LIST-ENTER_ACCOUNT_STATUS = '03'.

                LS_CONTENT_SUBMITENTERACCOUNT-ENTER_ACCOUNT_MODE = '2'. "1：提交入账（原始状态为未入账） 2：变更入账（原始状态为已入账和入账撤销

                CLEAR LS_CONTENT_SUBMITACC_ITM.
                LS_CONTENT_SUBMITACC_ITM-INVOICE_CODE = LV_INV_CODE.
                LS_CONTENT_SUBMITACC_ITM-INVOICE_NUMBER = LV_INV_NO.
                LS_CONTENT_SUBMITACC_ITM-ELEC_INVOICE_NUMBER = LV_INV_NO.
                LS_CONTENT_SUBMITACC_ITM-ENTER_ACCOUNT_STATUS = '06'.  "入账状态（02：已入账-企业所得税税前扣除；03：已入账-企业所得税不扣除；06：撤销入账）
                LS_CONTENT_SUBMITACC_ITM-ENTER_ACCOUNT_TIME = SY-DATUM+0(4) && '-' && SY-DATUM+4(2) && '-' && SY-DATUM+6(2).
                APPEND LS_CONTENT_SUBMITACC_ITM TO LS_CONTENT_SUBMITENTERACCOUNT-INV_DATA.
              ENDIF.
            ENDIF.
          ENDIF.

          "查询抵扣勾选数据
          IF LS_ZFIT078_HEAD-INVOICE_LINE CS 's' OR  "专用发票(纸质)
             LS_ZFIT078_HEAD-INVOICE_LINE CS 'b' OR  "专用发票(电子)
            LS_ZFIT078_HEAD-INVOICE_LINE CS 'bs' OR  "电子发票（增值税专用发票)
            LS_ZFIT078_HEAD-INVOICE_LINE CS 'es' OR  "数电纸质专用发票
            LS_ZFIT078_HEAD-INVOICE_LINE CS '17' .  "海关缴款书

            CLEAR LS_INV_CHECK_LIST.
            READ TABLE LT_INV_CHECK_LIST INTO LS_INV_CHECK_LIST
              WITH KEY ELEC_INVOICE_NUMBER = LS_JSD_DATA-ZYSFPHM
              BINARY SEARCH.
            IF SY-SUBRC = 0.

              "准备抵扣勾选数据
              IF LS_INV_CHECK_LIST-CHECK_STATUS = '1'. "勾选状态：0-未勾选1-已勾选， -1-采集缴款书,不能勾选.
                IF LS_ZFIT078_HEAD-INVOICE_LINE CS '17'. "海关缴款书

                  LS_CONTENT_CHECKLISTNEW_HG-JKSBZ = '1'. "缴款书标志0-勾选发票 1-勾选缴款书 2-代扣代缴完税凭证。不传默认0
                  LS_CONTENT_CHECKLISTNEW_HG-GX_USER_NAME = 'VIM'. "勾选人名称
                  LS_CONTENT_CHECKLISTNEW_HG-DEDUCTIBLE_MODE = '-1'. "1：抵扣勾选（默认） -1：取消抵扣勾选 4：不抵扣勾选 -4：取消不抵扣勾选 5：退税勾选 -5：取消退税勾选

                  CLEAR LS_CONTENT_CHECKLISTNEW_ITM.
                  LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_CODE = LV_INV_CODE.
                  LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_NUM = LV_INV_NO.
                  APPEND LS_CONTENT_CHECKLISTNEW_ITM TO LS_CONTENT_CHECKLISTNEW_HG-INV_DATA.

                ELSE.
                  LS_CONTENT_CHECKLISTNEW_INV-JKSBZ = '0'.             "缴款书标志0-勾选发票 1-勾选缴款书 2-代扣代缴完税凭证。不传默认0
                  LS_CONTENT_CHECKLISTNEW_INV-GX_USER_NAME = 'VIM'.    "勾选人名称
                  LS_CONTENT_CHECKLISTNEW_INV-DEDUCTIBLE_MODE = '-1'. "1：抵扣勾选（默认） -1：取消抵扣勾选 4：不抵扣勾选 -4：取消不抵扣勾选 5：退税勾选 -5：取消退税勾选

                  CLEAR LS_CONTENT_CHECKLISTNEW_ITM.
                  LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_CODE = LV_INV_CODE.
                  LS_CONTENT_CHECKLISTNEW_ITM-INVOICE_NUM = LV_INV_NO.
                  APPEND LS_CONTENT_CHECKLISTNEW_ITM TO LS_CONTENT_CHECKLISTNEW_INV-INV_DATA.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDIF.

        ENDIF.
      ENDLOOP.

      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL OR LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL
        OR LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.

        LV_NEED_SYNC_FLAG = 'X'.
        WRITE: / '开始进项诺诺平台：撤销入账、撤销抵扣勾选..............'.
      ENDIF.

      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL.
        LV_NEED_SYNCENTERACCOUNT = 'X'.

        "诺诺发票接口-提交/变更入账数据
        CLEAR: LS_MSG.
        CALL FUNCTION 'ZFIFM_INV_SUBMITENTERACCOUNT'
          EXPORTING
            IS_CONTENT = LS_CONTENT_SUBMITENTERACCOUNT
          IMPORTING
            ES_MSG     = LS_MSG.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-撤销入账数据失败，原因：',  LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-撤销入账数据已成功执行'.
        ENDIF.
      ENDIF.


      "诺诺发票接口-勾选抵扣-发票数据
      IF LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL.
        CLEAR:
          LS_MSG,
          LV_TASK_NO.
        CALL FUNCTION 'ZFIFM_INV_CHECK_LIST_NEW'
          EXPORTING
            IS_CONTENT = LS_CONTENT_CHECKLISTNEW_INV
          IMPORTING
            ES_MSG     = LS_MSG
            EV_TASK_NO = LV_TASK_NO.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-撤销勾选抵扣(发票数据)失败，原因：',  LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-撤销勾选抵扣(发票数据)已成功执行'.
        ENDIF.
      ENDIF.

      "诺诺发票接口-勾选抵扣-海关缴款书数据
      IF LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.
        CLEAR:
          LS_MSG,
          LV_TASK_NO.
        CALL FUNCTION 'ZFIFM_INV_CHECK_LIST_NEW'
          EXPORTING
            IS_CONTENT = LS_CONTENT_CHECKLISTNEW_HG
          IMPORTING
            ES_MSG     = LS_MSG
            EV_TASK_NO = LV_TASK_NO.
        IF LS_MSG-TYPE = 'E'.
          LV_MSG_STR = LS_MSG-MESSAGE.
          WRITE: / '诺诺发票接口-撤销勾选抵扣(海关缴款书数据)失败，原因：',  LV_MSG_STR.
          RETURN.
        ELSE.
          WRITE: / '诺诺发票接口-撤销勾选抵扣(海关缴款书数据)已成功执行'.
        ENDIF.
      ENDIF.

      IF LS_CONTENT_SUBMITENTERACCOUNT IS NOT INITIAL OR LS_CONTENT_CHECKLISTNEW_INV IS NOT INITIAL
        OR LS_CONTENT_CHECKLISTNEW_HG IS NOT INITIAL.
        WRITE: / '已完成诺诺平台：撤销入账、提交撤销抵扣勾选..............'.
        WRITE:/.
      ENDIF.

      IF  LV_NEED_SYNCENTERACCOUNT = 'X'.

        LV_ZKPSJ_BEGDA_TMP = LV_ZKPSJ_BEGDA.
        LV_ZKPSJ_ENDDA_TMP = LV_ZKPSJ_ENDDA.

        "获取发票列表数据开始
**********************************************************************
        LV_ZKPSJ_BEGDA_TMP1 = LV_ZKPSJ_BEGDA + 90.
        IF LV_ZKPSJ_BEGDA_TMP1 <  LV_ZKPSJ_ENDDA. "获取发票列表不能大于91天

          DO.
            LV_ZKPSJ_BEGDA_TMP1 = LV_ZKPSJ_BEGDA_TMP + 90.

            IF LV_ZKPSJ_BEGDA_TMP1 >= LV_ZKPSJ_ENDDA.
              LV_ZKPSJ_ENDDA_TMP = LV_ZKPSJ_ENDDA.
            ELSE.
              LV_ZKPSJ_ENDDA_TMP = LV_ZKPSJ_BEGDA_TMP + 90.
            ENDIF.

            LS_CONTENT_SYNCENTERACCOUNT-WRZ-KPRQQ = LV_ZKPSJ_BEGDA_TMP+0(4) && '-' && LV_ZKPSJ_BEGDA_TMP+4(2) && '-' && LV_ZKPSJ_BEGDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-WRZ-KPRQZ =  LV_ZKPSJ_ENDDA_TMP+0(4) && '-' && LV_ZKPSJ_ENDDA_TMP+4(2) && '-' && LV_ZKPSJ_ENDDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-KC_YRZ-KPRQQ = LV_ZKPSJ_BEGDA_TMP+0(4) && '-' && LV_ZKPSJ_BEGDA_TMP+4(2) && '-' && LV_ZKPSJ_BEGDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-KC_YRZ-KPRQZ =  LV_ZKPSJ_ENDDA_TMP+0(4) && '-' && LV_ZKPSJ_ENDDA_TMP+4(2) && '-' && LV_ZKPSJ_ENDDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-BKC_YRZ-KPRQQ = LV_ZKPSJ_BEGDA_TMP+0(4) && '-' && LV_ZKPSJ_BEGDA_TMP+4(2) && '-' && LV_ZKPSJ_BEGDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-BKC_YRZ-KPRQZ =  LV_ZKPSJ_ENDDA_TMP+0(4) && '-' && LV_ZKPSJ_ENDDA_TMP+4(2) && '-' && LV_ZKPSJ_ENDDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-CXRZ-KPRQQ = LV_ZKPSJ_BEGDA_TMP+0(4) && '-' && LV_ZKPSJ_BEGDA_TMP+4(2) && '-' && LV_ZKPSJ_BEGDA_TMP+6(2).
            LS_CONTENT_SYNCENTERACCOUNT-CXRZ-KPRQZ = LV_ZKPSJ_ENDDA_TMP+0(4) && '-' && LV_ZKPSJ_ENDDA_TMP+4(2) && '-' && LV_ZKPSJ_ENDDA_TMP+6(2).
            "诺诺发票接口-同步入账数据
            CLEAR: LS_MSG.
            CALL FUNCTION 'ZFIFM_INV_SYNCENTERACCOUNT'
              EXPORTING
                IS_CONTENT = LS_CONTENT_SYNCENTERACCOUNT
              IMPORTING
                ES_MSG     = LS_MSG.
            IF LS_MSG-TYPE = 'E'.
              LV_MSG_STR = LS_MSG-MESSAGE.
              WRITE: / '诺诺发票接口-同步入账数据失败，原因：',  LV_MSG_STR.
              RETURN.
            ELSE.
              WRITE: / '诺诺发票接口-同步入账数据已成功执行'.
            ENDIF.

            LV_ZKPSJ_BEGDA_TMP = LV_ZKPSJ_ENDDA_TMP + 1.

            IF LV_ZKPSJ_ENDDA_TMP >= LV_ZKPSJ_ENDDA.
              EXIT.
            ENDIF.
          ENDDO.

        ELSE.

          LS_CONTENT_SYNCENTERACCOUNT-WRZ-KPRQQ = LV_ZKPSJ_BEGDA+0(4) && '-' && LV_ZKPSJ_BEGDA+4(2) && '-' && LV_ZKPSJ_BEGDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-WRZ-KPRQZ =  LV_ZKPSJ_ENDDA+0(4) && '-' && LV_ZKPSJ_ENDDA+4(2) && '-' && LV_ZKPSJ_ENDDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-KC_YRZ-KPRQQ = LV_ZKPSJ_BEGDA+0(4) && '-' && LV_ZKPSJ_BEGDA+4(2) && '-' && LV_ZKPSJ_BEGDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-KC_YRZ-KPRQZ =  LV_ZKPSJ_ENDDA+0(4) && '-' && LV_ZKPSJ_ENDDA+4(2) && '-' && LV_ZKPSJ_ENDDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-BKC_YRZ-KPRQQ = LV_ZKPSJ_BEGDA+0(4) && '-' && LV_ZKPSJ_BEGDA+4(2) && '-' && LV_ZKPSJ_BEGDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-BKC_YRZ-KPRQZ =  LV_ZKPSJ_ENDDA+0(4) && '-' && LV_ZKPSJ_ENDDA+4(2) && '-' && LV_ZKPSJ_ENDDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-CXRZ-KPRQQ = LV_ZKPSJ_BEGDA+0(4) && '-' && LV_ZKPSJ_BEGDA+4(2) && '-' && LV_ZKPSJ_BEGDA+6(2).
          LS_CONTENT_SYNCENTERACCOUNT-CXRZ-KPRQZ = LV_ZKPSJ_ENDDA+0(4) && '-' && LV_ZKPSJ_ENDDA+4(2) && '-' && LV_ZKPSJ_ENDDA+6(2).
          "诺诺发票接口-同步入账数据
          CLEAR: LS_MSG.
          CALL FUNCTION 'ZFIFM_INV_SYNCENTERACCOUNT'
            EXPORTING
              IS_CONTENT = LS_CONTENT_SYNCENTERACCOUNT
            IMPORTING
              ES_MSG     = LS_MSG.
          IF LS_MSG-TYPE = 'E'.
            LV_MSG_STR = LS_MSG-MESSAGE.
            WRITE: / '诺诺发票接口-同步入账数据失败，原因：',  LV_MSG_STR.
            RETURN.
          ELSE.
            WRITE: / '诺诺发票接口-同步入账数据已成功执行'.
          ENDIF.

        ENDIF.

      ENDIF.

      IF LV_NEED_SYNC_FLAG IS INITIAL.
        WRITE: / '无发票数据需提交入账，入账同步税局、提交抵扣勾选'.
      ENDIF.

    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_POST_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_POST_DATA .
  DATA:
    "LT_R_JSDZT_TMP TYPE RANGE OF ZFIT079_HEAD-JSDZT WITH HEADER LINE,
    LT_R_ZFPZT_TMP TYPE RANGE OF ZFIT078_HIS-ZFPZT WITH HEADER LINE.

  "取过账数据
  SELECT
    A~JSDDH
    B~JSDHH
    A~ZFPHM
    B~ZYSFPHM
    A~ZYWLX
    A~JSDLX
    A~JSDZT
    A~ZFPLX
    A~ZKPSJ
    A~BUKRS
    A~ZGFMC
    A~LIFNR
    A~ZXFMC
    A~ZHSJE
    A~ZHJSE
    A~ZBHSJE
    A~BELNR
    A~GJAHR
    A~CRNAM
    A~CHDAT
    A~CHTIM
    INTO CORRESPONDING FIELDS OF TABLE GT_JSD_DATA
    FROM ZFIT079_HEAD AS A
    JOIN ZFIT079_ITEM AS B
      ON A~JSDDH = B~JSDDH
   WHERE A~JSDDH IN S_JSDDH
     AND B~ZYSFPHM IN S_ZFPHM
     AND A~BELNR IN S_BELNR
     AND A~GJAHR IN S_GJAHR
     AND A~CHDAT IN S_DATE
     AND A~BELNR <> SPACE
     AND A~ZYWLX IN ('01', '03'). "国内、寄售
  "AND A~JSDZT <> '04'. "作废

  IF P_NOHZ IS NOT INITIAL.
    DELETE GT_JSD_DATA WHERE ZHSJE < 0.
  ENDIF.

  IF GT_JSD_DATA[] IS INITIAL.
    GV_ERROR = 'X'.
    WRITE / '无数据，请检查查询条件'(T01).
    RETURN.
  ENDIF.

  "考虑作废情况，删除重复项取最新的单据
  SORT GT_JSD_DATA BY ZYSFPHM ZFPHM CHDAT DESCENDING CHTIM DESCENDING.
  DELETE ADJACENT DUPLICATES FROM GT_JSD_DATA COMPARING ZYSFPHM ZFPHM.


  DATA:
    LT_RG_JSDDH_TMP TYPE RANGE OF ZFIT078_HIS-JSDDH WITH HEADER LINE,
    LT_JSD_DATA_TMP TYPE STANDARD TABLE OF TY_JSD_DATA.

  "过滤掉拆分发票后，过账状态不一致的发票
  LOOP AT GT_JSD_DATA INTO DATA(LS_JSD_DATA) WHERE ZFPHM CS '-CF'.
    APPEND LS_JSD_DATA TO LT_JSD_DATA_TMP.
  ENDLOOP.

  IF LT_JSD_DATA_TMP IS NOT INITIAL.

    SELECT *
      INTO TABLE @DATA(LT_CF_HIS)
      FROM ZFIT078_HIS
       FOR ALL ENTRIES IN @LT_JSD_DATA_TMP
     WHERE ZFPHM = @LT_JSD_DATA_TMP-ZYSFPHM
       AND JSDDH = @LT_JSD_DATA_TMP-JSDDH.

    IF SY-SUBRC = 0.
      "删除最终状态为冲销的发票结算单
      LOOP AT LT_CF_HIS INTO DATA(LS_CF_HIS) WHERE ZFPZT = '45'.
        CLEAR LT_RG_JSDDH_TMP.
        LT_RG_JSDDH_TMP-SIGN = 'I'.
        LT_RG_JSDDH_TMP-OPTION = 'EQ'.
        LT_RG_JSDDH_TMP-LOW = LS_CF_HIS-JSDDH.
        APPEND LT_RG_JSDDH_TMP.
      ENDLOOP.

      IF LT_RG_JSDDH_TMP[] IS NOT INITIAL.
        SORT LT_RG_JSDDH_TMP.
        DELETE ADJACENT DUPLICATES FROM LT_RG_JSDDH_TMP.

        DELETE LT_CF_HIS WHERE JSDDH IN LT_RG_JSDDH_TMP.
      ENDIF.


      SORT LT_CF_HIS BY ZFPHM JSDDH ZFPZT DESCENDING.
      DELETE ADJACENT DUPLICATES FROM LT_CF_HIS COMPARING ZFPHM JSDDH.

      SORT LT_CF_HIS BY ZFPHM ZFPZT.

      LOOP AT LT_CF_HIS INTO LS_CF_HIS.
        IF LS_CF_HIS-ZFPZT IS NOT  INITIAL.
          CLEAR LT_R_ZFPZT_TMP.
          LT_R_ZFPZT_TMP-SIGN = 'I'.
          LT_R_ZFPZT_TMP-OPTION = 'EQ'.
          LT_R_ZFPZT_TMP-LOW = LS_CF_HIS-ZFPZT.
          APPEND LT_R_ZFPZT_TMP.
        ENDIF.

        AT END OF ZFPHM.
          SORT LT_R_ZFPZT_TMP.
          DELETE ADJACENT DUPLICATES FROM LT_R_ZFPZT_TMP COMPARING ALL FIELDS.

          IF LINES( LT_R_ZFPZT_TMP ) > 1.
            IF '40' IN LT_R_ZFPZT_TMP. "发票包含已经过账且有未过账的单据，则删除该发票
              DELETE GT_JSD_DATA WHERE ZYSFPHM = LS_CF_HIS-ZFPHM .
            ENDIF.
          ENDIF.
          REFRESH LT_R_ZFPZT_TMP[].
        ENDAT.
      ENDLOOP.

    ENDIF.


*    "根据原始发票号，取拆分的发票结算单数据
*    SELECT
*      B~ZYSFPHM,
*      A~JSDDH,
*      B~JSDHH,
*      A~ZFPHM,
*      A~JSDZT,
*      A~BELNR,
*      A~GJAHR
*      INTO TABLE @DATA(LT_JSD_DATA_CF)
*      FROM ZFIT079_HEAD AS A
*      JOIN ZFIT079_ITEM AS B
*        ON A~JSDDH = B~JSDDH
*       FOR ALL ENTRIES IN @LT_JSD_DATA_TMP
*     WHERE B~ZYSFPHM = @LT_JSD_DATA_TMP-ZYSFPHM
*       AND A~ZYWLX IN ('01', '03'). "国内、寄售
*    " AND A~JSDZT <> '04'.  "作废
*
*    "考虑作废情况，删除重复项取最新的单据
*    SORT LT_JSD_DATA_CF BY ZYSFPHM ZFPHM JSDDH DESCENDING.
*    DELETE ADJACENT DUPLICATES FROM LT_JSD_DATA_CF COMPARING ZYSFPHM ZFPHM.
*
*    SORT LT_JSD_DATA_CF BY ZYSFPHM JSDZT.
*
*    LOOP AT LT_JSD_DATA_CF INTO DATA(LS_JSD_DATA_CF).
*      IF LS_JSD_DATA_CF-JSDZT IS NOT  INITIAL.
*        CLEAR LT_R_JSDZT_TMP.
*        LT_R_JSDZT_TMP-SIGN = 'I'.
*        LT_R_JSDZT_TMP-OPTION = 'EQ'.
*        LT_R_JSDZT_TMP-LOW = LS_JSD_DATA_CF-JSDZT.
*        APPEND LT_R_JSDZT_TMP.
*      ENDIF.
*
*      AT END OF ZYSFPHM.
*        SORT LT_R_JSDZT_TMP.
*        DELETE ADJACENT DUPLICATES FROM LT_R_JSDZT_TMP COMPARING ALL FIELDS.
*
*        IF LINES( LT_R_JSDZT_TMP ) > 1.
*          IF '05' IN LT_R_JSDZT_TMP. "发票包含已经过账且有未过账的单据，则删除该发票
*            DELETE GT_JSD_DATA WHERE ZYSFPHM = LS_JSD_DATA_CF-ZYSFPHM .
*          ENDIF.
*        ENDIF.
*        REFRESH LT_R_JSDZT_TMP[].
*      ENDAT.
*    ENDLOOP.
  ENDIF.

  SORT GT_JSD_DATA BY ZYSFPHM JSDZT.
  DELETE ADJACENT DUPLICATES FROM GT_JSD_DATA COMPARING ZYSFPHM JSDZT.

  "保留最新状态的发票
  SORT GT_JSD_DATA BY ZYSFPHM CHDAT DESCENDING CHTIM DESCENDING.
  DELETE ADJACENT DUPLICATES FROM GT_JSD_DATA COMPARING ZYSFPHM.

  LOOP AT GT_JSD_DATA.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_JSD_DATA-ZYWLX 'ZDO_ZYWLX1' CHANGING GT_JSD_DATA-ZYWLX_TXT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_JSD_DATA-JSDLX 'ZDO_JSDLX'  CHANGING GT_JSD_DATA-JSDLX_TXT.
    PERFORM FRM_READ_DOMAIN_TEXT USING GT_JSD_DATA-JSDZT 'ZDO_JSDZT'  CHANGING GT_JSD_DATA-JSDZT_TXT.
    MODIFY GT_JSD_DATA.
  ENDLOOP.

  IF GT_JSD_DATA[] IS INITIAL.
    GV_ERROR = 'X'.
    WRITE / '无数据，请检查查询条件'(T01).
    RETURN.
  ENDIF.

*  DATA: LV_INV_COUNT TYPE I.
*  LV_INV_COUNT = LINES( GT_JSD_DATA[] ).
*
*  IF LV_INV_COUNT > 100.
*    IF P_SEND IS NOT INITIAL.
*      MESSAGE '发票条目数大于100，诺诺接口不支持' TYPE 'S' DISPLAY LIKE 'E'.
*      LEAVE LIST-PROCESSING.
*    ELSE.
*      MESSAGE '发票条目数大于100，诺诺接口不支持' TYPE 'I'.
*    ENDIF.
*  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .

  DATA:
    LR_TABLE     TYPE REF TO CL_SALV_TABLE,
    LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
    LR_FUNC_LIST TYPE REF TO CL_SALV_FUNCTIONS_LIST,
    LR_EVENTS    TYPE REF TO CL_SALV_EVENTS,
    LR_SELECTS   TYPE REF TO CL_SALV_SELECTIONS,
    LR_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE,
    LR_COLUMN    TYPE REF TO CL_SALV_COLUMN_TABLE,
    LR_LAYOUT    TYPE REF TO CL_SALV_LAYOUT,
    LS_DDIC      TYPE SALV_S_DDIC_REFERENCE,
    LS_KEY       TYPE SALV_S_LAYOUT_KEY.

  CHECK GV_ERROR IS INITIAL.
  CHECK P_SEND IS INITIAL.

  TRY.
      CL_SALV_TABLE=>FACTORY(
        IMPORTING
          R_SALV_TABLE = LR_TABLE
        CHANGING
          T_TABLE      = GT_JSD_DATA[]
      ).
    CATCH CX_SALV_MSG.
  ENDTRY.

  "设置列Lable
  LR_COLUMNS = LR_TABLE->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( 'X' ).
  LR_COLUMNS->SET_KEY_FIXATION( 'X' ).

  "显示设置
  LR_DISPLAY = LR_TABLE->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' ). "设置颜色间隔显示

  "设置选择模式
  LR_SELECTS = LR_TABLE->GET_SELECTIONS( ).
  LR_SELECTS->SET_SELECTION_MODE( CL_SALV_SELECTIONS=>IF_SALV_C_SELECTION_MODE~CELL ).

  "STAUTS ALV 标准功能
  LR_FUNC_LIST = LR_TABLE->GET_FUNCTIONS( ).
  LR_FUNC_LIST->SET_ALL( 'X' ).

  "打开Layout保存功能
  LR_LAYOUT = LR_TABLE->GET_LAYOUT( ).
  LS_KEY-REPORT = SY-REPID.
  LR_LAYOUT->SET_KEY( LS_KEY ).
  LR_LAYOUT->SET_DEFAULT( ABAP_TRUE ).
  LR_LAYOUT->SET_SAVE_RESTRICTION( IF_SALV_C_LAYOUT=>RESTRICT_NONE ).

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ZYWLX' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'ZYWLX'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDLX' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'JSDLX'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDZT' ).
      LS_DDIC-TABLE = 'ZFIT079_HEAD'.
      LS_DDIC-FIELD = 'JSDZT'.
      LR_COLUMN->SET_DDIC_REFERENCE( LS_DDIC ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'ZYWLX_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H01 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H01 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H01 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDLX_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H02 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H02 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H02 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'JSDZT_TXT' ).
      LR_COLUMN->SET_SHORT_TEXT( TEXT-H03 ).
      LR_COLUMN->SET_MEDIUM_TEXT( TEXT-H03 ).
      LR_COLUMN->SET_LONG_TEXT( TEXT-H03 ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.


*  TRY .
*      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'EBELP' ).
*      LR_COLUMN->SET_KEY( 'X' ).
*      LR_COLUMN->SET_SHORT_TEXT( 'Item' ).
*      LR_COLUMN->SET_MEDIUM_TEXT( 'Item' ).
*      LR_COLUMN->SET_LONG_TEXT( 'Item' ).
*    CATCH CX_SALV_NOT_FOUND.
*  ENDTRY.

  LR_TABLE->DISPLAY( ).
ENDFORM.

FORM FRM_READ_DOMAIN_TEXT  USING    IV_KEY
                                IV_DOMNAME
                       CHANGING CV_TEXT.
  DATA:
    LS_TAB TYPE DD07V,
    LT_TAB TYPE STANDARD TABLE OF DD07V.

  CLEAR CV_TEXT.

  CALL FUNCTION 'DD_DOMVALUES_GET'
    EXPORTING
      DOMNAME        = IV_DOMNAME
      TEXT           = 'X'
    TABLES
      DD07V_TAB      = LT_TAB
    EXCEPTIONS
      WRONG_TEXTFLAG = 1
      OTHERS         = 2.

  IF SY-SUBRC <> 0.
    RETURN.
  ENDIF.

  LOOP AT LT_TAB INTO LS_TAB.
    IF LS_TAB-DOMVALUE_L = IV_KEY.
      CV_TEXT = LS_TAB-DDTEXT.
      EXIT.
    ENDIF.
  ENDLOOP.
ENDFORM.
